package com.example.interfacecall.exception;

import com.example.interfacecall.constans.ExceptionEnum;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;

public class BusinessException extends BaseException{
    private static final long serialVersionUID = 1L;
    private String causeType = ExceptionEnum.BUSINESS_EXCEPTION.toString();


    public BusinessException() {
    }

    public BusinessException(String message) {
        super(message, "500");
        super.setCauseType(causeType);
    }

    public BusinessException(String message, String code) {
        super(message, code);
        super.setCauseType(causeType);
    }

    public BusinessException(String message, String code, String data) {
        super(message, code, data);
        super.setCauseType(causeType);
    }

    public BusinessException(String message, String code, Map<String, Object> map) {
        super(message, code, map);
        super.setCauseType(causeType);
    }

    public BusinessException(String message, String code, Map<String, Object> map, String data) {
        super(message, code, map);
        super.setData(data);
        super.setCauseType(causeType);
    }

    public BusinessException(Throwable exception) {
        super(exception);
        super.setCauseType(causeType);
    }

    public BusinessException(String message, String code, Throwable exception) {
        super(message, code, exception);
        super.setCauseType(causeType);
    }

    public BusinessException(Throwable exception, String message, String code, Map<String, Object> map) {
        super(exception, message, code, map);
        super.setCauseType(causeType);
    }

    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try {
            throwable.printStackTrace(pw);
            return sw.toString();
        } finally {
            pw.close();
        }
    }
}
